package com.example.administrator.college02;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class BaseActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
    }

    public void showFragment(Class<? extends BaseFragment> beShowedFragment, String fragmentTag, Bundle bundle, boolean addBackStack) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        Fragment fragment = manager.findFragmentByTag(fragmentTag);
        transaction.setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_pop_enter, R.anim.fragment_pop_exist);
        try {
            fragment = beShowedFragment.newInstance();
            if (bundle != null) {
                fragment.setArguments(bundle);
            }
            transaction.add(android.R.id.content, fragment, fragmentTag);
        } catch (Exception e) {
        }
        if (addBackStack) {
            transaction.addToBackStack(fragmentTag);
        }
        transaction.commit();
    }
}
